var app = getApp()
var Utils = require('../../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inquiry: "",
    checkboxlist: [{
        text: "7天",
        checked: false
      },
      {
        text: "14天",
        checked: false
      },
      {
        text: "1个月",
        checked: false
      },
      {
        text: "2个月",
        checked: false
      },
      {
        text: "3个月",
        checked: false
      },
    ],
    upload_picture_list: [],
    typedate: 0
  }, //提交表单tit=远程开方&key_words=dianhuajizhen&back_orser=2020052610248505&zid=4&j_id=27
  infomationbtn(e) {
    console.log(e)
    var that = this
    let vals = e.detail.value;
    var upload_picture_list = that.data.upload_picture_list
    var typedate = that.data.typedate
    var key_words = that.data.key_words
    var timeleng = that.data.timeleng
    var tit = that.data.tit
    var ifzy = that.data.ifzy
    var money = that.data.money
    var arr = {
      'text': vals.zhengzhuang,
      'text2': vals.yaopin,
      'timleng': timeleng,
      'upload_picture_list': upload_picture_list,
      'typedate': typedate
    }
    var conets = JSON.stringify(arr)
    console.log(arr)
    if (vals.zhengzhuang == "") {
      wx.showToast({
        title: '提问至少10字',
        icon: 'none'
      })
    } else {
      if (that.data.back_orser) {
        var back_orser = that.data.back_orser
        var zid = that.data.zid
        var j_id = that.data.j_id
        wx.navigateTo({
          url: '/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi?inquiry=-1' + '&conets=' + conets + '&key_words=' + key_words + '&pinyin=' + key_words + '&tit=' + tit + '&back_orser=' + back_orser + '&zid=' + zid + '&j_id=' + j_id + '&ifzy=' + ifzy + '&money=' + money
        })
      } else {
        var zid = that.data.zid
        wx.navigateTo({
          url: '/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi?inquiry=' + this.data.inquiry + '&conets=' + conets + '&key_words=' + key_words + '&pinyin=' + key_words + '&tit=' + tit + '&ifzy=' + ifzy + '&zid=' + zid + '&money=' + money
        })
      }

    }
  },
  //删除图片
  deleteimg: function (e) {
    var that = this;
    var i = e.currentTarget.dataset.index;
    var imgArr = that.data.upload_picture_list;
    console.log(imgArr)
    imgArr.splice(i, 1);
    that.setData({
      upload_picture_list: imgArr,
      typedate: 0
    })
  },
  // 上传图片
  uploadimg: function () {
    let that = this;
    var uniacid = app.siteInfo.uniacid
    var data_arr = that.data.upload_picture_list;
    wx.chooseImage({
      count: 5,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        for (var i = 0; i < tempFilePaths.length; i++) {
          wx.uploadFile({
            url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadback&m=hyb_yl',
            filePath: tempFilePaths[i],
            name: 'upfile',
            formData: [],
            success: function (res) {
              console.log(res)
              data_arr.push(res.data)
              that.setData({
                upload_picture_list: data_arr,
                typedate: 1
              })
            }
          })
        }
      }
    })
  },
  // 选择开药时间
  checkcommon(e) {
    let checkboxlist = this.data.checkboxlist,
      i = e.currentTarget.dataset.i
    checkboxlist[i].checked = !checkboxlist[i].checked
    this.setData({
      checkboxlist,
      timeleng: e.currentTarget.dataset.timeleng
    })
  },
  /**
   * 生命周期函数--监听页面加载tit=远程开方&key_words=dianhuajizhen&back_orser=2020052610248505&zid=4&j_id=27
   */
  onLoad: function (options) {
    var that = this
    var bgc = wx.getStorageSync('color')
    var ifzy = options.ifzy
    var key_words = options.key_words
    if (options.zid) {
      that.setData({
        zid: options.zid,
      })
    }
    if (options.money) {
      that.setData({
        money: options.money,
      })
    }
    if (options.back_orser) {
      var zid = options.zid
      var j_id = options.j_id
      that.setData({
        back_orser: options.back_orser,
        zid: zid,
        j_id: j_id
      })
    }
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    app.util.request({
      'url': 'entry/wxapp/hzbingli.url',
      success: function (res) {
        that.setData({
          url: res.data,
        })
      }
    })
    that.setData({
      inquiry: options.inquiry,
      key_words: key_words,
      tit: options.tit,
      ifzy: ifzy
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})